﻿using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;

namespace Resource
{
    public class PersistPath
    {

        public static string basesourceActorPath = "Assets/baseresource/actor/";
        public static string basesourceUiPath = "Assets/baseresource/ui/";
        public static string basesourceLuaPath = "Assets/baseresource/script/";
        public static string basesourceEffectPath = "Assets/baseresource/effect/";
        public static string basesourceAnimatorPath = "Assets/baseresource/animator/";
        public static string basesourceAudioPath = "Assets/baseresource/audio/";
        public static string basesourceAtlasPath = "Assets/baseresource/atlas/";
        public static string basesourceMaterialPath = "Assets/baseresource/material/";
        public static string basesourceSpritePath = "Assets/baseresource/sprite2d/";
        public static string basesourceScenePath = "Assets/baseresource/scene/";
		
    }

    public class resbuilder
    {

        public static BuildTarget mTarget = getCurBuildTarget();

        private static BuildTarget getCurBuildTarget()
        {
            if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.iOS)
                return BuildTarget.iOS;
            else if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android)
                return BuildTarget.Android;
            else
                return BuildTarget.StandaloneWindows;
        }



        [MenuItem("Resources/Builder/Build All")]
        public static void editorBuildAll()
        {
            Debug.Log("build all begin " + System.DateTime.Now.ToString());


            Debug.Log("build all end " + System.DateTime.Now.ToString());
        }

        [MenuItem("Resources/Builder/BuildAsset")]
        public static void editorBuildAssets()
        {
            Debug.Log("build asset begin " + System.DateTime.Now.ToString());
            Object[] assets = Selection.GetFiltered(typeof(Object), SelectionMode.Assets);
			AssetImporter imp = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(assets[0]));

			AssetBundleBuild[] buildMap = new AssetBundleBuild[1];
			buildMap[0].assetBundleName = imp.assetBundleName;
			BuildPipeline.BuildAssetBundles("Assets/abs", buildMap, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);

			Debug.Log("assets bundles name:" + imp.assetBundleName);
			Debug.Log("build asset end " + System.DateTime.Now.ToString());
        }
		[MenuItem("Resources/Builder/Test")]
		static void BuildMapABs()
		{
			AssetBundleBuild[] buildMap = new AssetBundleBuild[2];

			buildMap[0].assetBundleName = "enemybundle";

			string[] enemyAssets = new string[2];
			enemyAssets[0] = "Assets/Textures/char_enemy_alienShip.jpg";
			enemyAssets[1] = "Assets/Textures/char_enemy_alienShip-damaged.jpg";

			buildMap[0].assetNames = enemyAssets;
			buildMap[1].assetBundleName = "herobundle";

			string[] heroAssets = new string[1];
			heroAssets[0] = "char_hero_beanMan";
			buildMap[1].assetNames = heroAssets;

			BuildPipeline.BuildAssetBundles("Assets/ABs", buildMap, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);
		}

	}
}
